//
//  THMangerTool.m
//  PublicProject
//
//  Created by TianHe_Wsk on 15/11/3.
//  Copyright © 2015年 H.D.X. All rights reserved.
//

#import "THMangerTool.h"



#import "Des.h"

@implementation THMangerTool


/*用户是否勾选记住账户 */
+(BOOL)IsKeepAccount{
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    if([[user objectForKey:KEEP] intValue]==1){
        return YES;
    }
    else{
        return NO;
    }
}
/**
 * 清理记住账户
 */
+(void)setKeepAccount:(BOOL)IsKeep{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    if(IsKeep){
        [user setObject:@"1" forKey:KEEP];
    }
    else{
        
        [user removeObjectForKey:KEEP];
        
    }
    [user synchronize];
}



/*用户是否登录*/
+(BOOL)isLogin{
    
    if([self getAccountInfo].key.length < 1||[[self getAccountInfo].key isEqualToString:@"null"]){
        
        return NO;
    }
    else{
        return YES;
    }
}

/**
 *  注销 或者修改密码
 */
+(void)removeAccount{
    
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:USERINFO];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [THUserInfoModel writeDataArray:[[[NSArray alloc] init] mutableCopy]   ModelKey:USERINFO];

}

/**
 *  获取版本号
 */
+(NSString*)getVersion:(BOOL)hiddinBuild{
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    if(hiddinBuild){
           return [NSString stringWithFormat:@"%@",app_Version];
    }
    else {
            NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
            return [NSString stringWithFormat:@"%@（%@）",app_Version,app_build];
    }
}

/**
 *  获取APP名称
 */
+(NSString*)getAppName{
    //    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    
    NSString *app_Name =  NSPublicLocalizedString(@"CFBundleDisplayNames", @"");
    
    return app_Name;
}
/**
 *  获取APP类别 Happyi | THRC
 */
+(NSString*)getAppType{
    
    NSString *app_Type =  NSPublicLocalizedString(@"APPType", @"");
    
    return app_Type;
}

/**
 * 是否首次进入APP
 */
+(BOOL)isStatrOpenApp{
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
   
    if([[user objectForKey:[NSString stringWithFormat:@"%@",START]] intValue]==1){
        return NO;
        
    }
    else{
        return YES;
    }
}

/**
 *保存用户已经进入首页
 */
+(void)savetStatrOpenApp{
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user setObject:@"1" forKey:[NSString stringWithFormat:@"%@",START]];
    [user synchronize];
    
}

/**
 *用户是否进行过新手指引
 */
+(BOOL)isPerfect{

    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    if([[user objectForKey:[NSString stringWithFormat:@"%@-%@",START,[self getKey]]] intValue]==1){
        return NO;
    }
    else{
        THUserInfoModel *user=[self getAccountInfo];
        if(user.realName.length>0){
            return NO;
        }
        return YES;
    }
}

/**
 *保存用户是否进行过新手指引
 */
+(void)savePerfect{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user setObject:@"1" forKey:[NSString stringWithFormat:@"%@-%@",START,[self getKey]]];
    [user synchronize];
}


/**
 *  保存账号密码(仅仅是账号密码)
 */
+(void)saveAccountInfo:(NSDictionary*)accountDict{
    
    //非空
    if(accountDict){
        /**
         *  注 : 因后台会返回<null>字符串  如果是null则保存空
         */
       NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
        
      [userdefaults setObject:accountDict forKey:USERACCOUT];
        
      [userdefaults synchronize];
    }
}

/**
 *  保存账户信息 模型信息
 */
+(void)saveAccountModel:(THUserInfoModel*)userModel{
    
    [THUserInfoModel writeDataArray:[@[userModel] mutableCopy] ModelKey:USERINFO];
    
}

/**
 *  获取用户账号信息 模型信息
 */
+ (THUserInfoModel*)getAccountInfo{
    NSArray *a=[THUserInfoModel readDataArrayByModelKey:USERINFO];
    THUserInfoModel * accountInfo=[[THUserInfoModel alloc] init];
    
    if(a.count>0){
        accountInfo= (THUserInfoModel*) a[0];
    }
    
    return accountInfo;
    
    
}

/**
 *  获取用户口令
 */
+ (NSString*)getKey{
    
    if ([self getAccountInfo].key.length<1) {
        
        return @"admin";
        
    }
    else{
        return [NSString stringWithFormat:@"%@",[self getAccountInfo].key];
    }
    
}

/**
 *  获取账号密码
 */
+ (NSDictionary*)getKeepAccout{
    
   return [[NSUserDefaults standardUserDefaults] objectForKey:USERACCOUT];
    
}


/**
 *   检测用户是否推送了版本更新 首先要有推送 其次推送的版本高于用户当前版本 返回AppStore的路径
 */
+ (NSDictionary*)getJpushVersion{
    
    //查找系统推送记录
    NSDictionary *sqlda=[FMDataSqlManger selectTable:@"et_message" where:[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"type",nil]];
    if([sqlda allKeys].count<1){
        return nil;
    }
    else{
        NSDictionary *versionDict=[UtilCheck dictionaryWithJsonString:[sqlda objectForKey:@"content"]];
        
        if([[versionDict allKeys] containsObject:@"Version"]){
            //当前版本小于服务器版本为真
            if ([[versionDict objectForKey:@"Version"] compare:[self getVersion] options:NSNumericSearch] == NSOrderedDescending){
                //版本高于当前版本
                return versionDict;
            }
            else{
              //版本不高于当前版本
             [FMDataSqlManger deleteTable:@"et_message" condition:@"type=0"];
                return nil;
            }
            
        }
        else{
            //版本不高于当前版本
            [FMDataSqlManger deleteTable:@"et_message" condition:@"type=0"];
            
            return nil;
        }
        
    }
}

/**
 *保存分享数据
 */
+(void)saveShareData:(NSDictionary*)shareDice{
    
    [[NSUserDefaults standardUserDefaults] setObject:shareDice forKey:SHARE];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
 
}
/**
 *获取保存分享数据
 */
+(NSDictionary*)getShareData{
    
    NSMutableDictionary *dict=[[NSMutableDictionary alloc] initWithCapacity:0];
    dict=[NSMutableDictionary dictionaryWithDictionary:[[[NSUserDefaults  standardUserDefaults] objectForKey:SHARE] copy]];
    
    
    if (![[dict allKeys] containsObject:@"content"]) {
        [dict setObject:[NSString stringWithFormat:@" ...来自%@的分享",[THMangerTool getAppName]] forKey:@"content"];
    }else{
        
        NSString *content=[dict objectForKey:@"content"];
        if(content.length>80){
         
            content=[content substringWithRange:NSMakeRange(0, 80)];
            [dict setObject:content forKey:@"content"];
        }
     
        
    }
    
    if (![[dict allKeys] containsObject:@"shareurl"]) {
        [dict setObject:[NSString stringWithFormat:@"http://www.baidu.com"] forKey:@"shareurl"];
    }
    
    if (![[dict allKeys] containsObject:@"description"]) {
        [dict setObject:[NSString stringWithFormat:@"显而易见 这里是问题描述"] forKey:@"description"];
    }
    else{
        NSString *content=[dict objectForKey:@"description"];
        if(content.length>80){
            
            content=[content substringWithRange:NSMakeRange(0, 80)];
            [dict setObject:content forKey:@"description"];
        }
    }
 
    return dict;
}

 

/**
 *获取用户修改头像时间
 */
+(NSString*)setUpHeadDateTime:(BOOL)isOnliytime{
    
    
    //更新缓存
    if([[[NSUserDefaults standardUserDefaults] objectForKey:HEADIMAGETIME] allKeys].count>0){
        
        NSMutableDictionary *temp=[NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:HEADIMAGETIME]];
        if(isOnliytime){
            NSString *dataTime=[UtilCheck stringByDate:[NSDate date] dateFormatter:@"yyyy-MM-dd HH:mm:ss"];
            
            [[NSUserDefaults standardUserDefaults] setObject:[NSDictionary dictionaryWithObjectsAndKeys:dataTime,@"apptime", nil] forKey:HEADIMAGETIME];
            [[NSUserDefaults standardUserDefaults] synchronize];
    
            return [UtilCheck clearSpace:dataTime isends:NO];
        }
        else{
            //六个小时更新一次数据  永不自动更新
            if([UtilCheck TimeCache:[NSString stringWithFormat:@"%@",[temp objectForKey:@"apptime"]]]>=18800*IMAGE_TIME)
            {
                NSString *dataTime=[UtilCheck stringByDate:[NSDate date] dateFormatter:@"yyyy-MM-dd HH:mm:ss"];
                
                [[NSUserDefaults standardUserDefaults] setObject:[NSDictionary dictionaryWithObjectsAndKeys:dataTime,@"apptime", nil] forKey:HEADIMAGETIME];
                [[NSUserDefaults standardUserDefaults] synchronize];
                            NSLog(@"dataTime:%@",dataTime);
                
                return  [UtilCheck clearSpace:dataTime isends:NO];
            }
            else{
                if([[temp allKeys] containsObject:@"apptime"]){
                                NSLog(@"dataTime:%@",[temp objectForKey:@"apptime"]);
                return  [UtilCheck clearSpace:[NSString stringWithFormat:@"%@",[temp objectForKey:@"apptime"]] isends:NO];;
                    
                }
                else{
                    
                    NSString *dataTime=[UtilCheck stringByDate:[NSDate date] dateFormatter:@"yyyy-MM-dd HH:mm:ss"];
                    
                    [[NSUserDefaults standardUserDefaults] setObject:[NSDictionary dictionaryWithObjectsAndKeys:dataTime,@"apptime", nil] forKey:HEADIMAGETIME];
                    [[NSUserDefaults standardUserDefaults] synchronize];
                                NSLog(@"dataTime:%@",dataTime);
                    return [UtilCheck clearSpace:dataTime isends:NO];
                }
            }
        }
    }
    else {
        
        NSString *dataTime=[UtilCheck stringByDate:[NSDate date] dateFormatter:@"yyyy-MM-dd HH:mm:ss"];
        
        [[NSUserDefaults standardUserDefaults] setObject:[NSDictionary dictionaryWithObjectsAndKeys:dataTime,@"apptime", nil] forKey:HEADIMAGETIME];
        [[NSUserDefaults standardUserDefaults] synchronize];
                    NSLog(@"dataTime:%@",dataTime);
        return  [UtilCheck clearSpace:dataTime isends:NO];
    }
 
}

/**
 *是否出在审核阶段 默认在审核
 */
+(BOOL)isAPPStoreExamine{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    //在审核
    if([[user objectForKey:[NSString stringWithFormat:@"%@",APPExamine]] intValue]!=2 ){
        return YES;
    }
    else{
        return NO;
    }
}

/**
 *修改审核阶段 IsAPPStore YES  在审核
 */
+(void)setAPPStoreExamine:(BOOL)IsAPPStore{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
 
    if(IsAPPStore){
        //在审核
        [user setObject:@"1" forKey:[NSString stringWithFormat:@"%@",APPExamine]];
    }
    else{
        //没有在审核
        [user setObject:@"2" forKey:[NSString stringWithFormat:@"%@",APPExamine]];
    }
        [user synchronize];
}

#pragma mark 服务器地址
/**
 *  获取当前APP请求地址
 *
 *  @return
 */
+ (NSString*)getUsedHost{
    
    NSString *usedHost;
    
    BOOL UserSelected = [[NSUserDefaults standardUserDefaults] boolForKey:IS_USER_SElELECTED];
    
    if (!UserSelected) {
        usedHost = [self getRecommendHost];
    }
    else {
        usedHost = [self getUserHost];
    }
    return usedHost;
}


/**
 获取用户选择的自己添加的服务器地址

 @return 用户返回的服务器地址
 */
+ (NSString *)getUserHost {
    
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
    NSString *userServer = [userDefaults objectForKey:USER_SERVER];
   
    if ([Toolobject IsEmptyString:userServer]) {
        userServer = HOST;
    }
    return userServer;
}

/**
 *   当用户选择自己添加的服务器地址时调用
 *   @param host  eg: http://www.hid.s:8080
 */
+(BOOL)setUserHost:(NSString *)host {
    
    [[NSUserDefaults standardUserDefaults] setObject:host forKey:USER_SERVER];
    
    if (![host hasPrefix:@"http://"]) {
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"changeURL.perfectURL"]];
        return NO;
    }
    
    // 用户选择了服务器地址
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:IS_USER_SElELECTED];
    return YES;
}

/**
 *  获取系统推荐服务器地址
 *
 *  @return
 */
+ (NSString*)getRecommendHost{
    
    
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
    
//   [userDefaults setObject:@"" forKey:RECOMMEND_SERVER];
    
    NSString *host = [userDefaults objectForKey:RECOMMEND_SERVER];
    
    if ([Toolobject IsEmptyString:host]) {
        host = HOST;
        [userDefaults setObject:host forKey:RECOMMEND_SERVER];
    }
    return host;
}

/**
 *  获取请求地址列表
 *
 *  @return
 */
+ (NSMutableArray *)getHostList {
    
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
    NSMutableArray *hostArray= [NSMutableArray arrayWithArray:[userDefaults objectForKey:ADD_SERVERS]];
    return hostArray;
}

/**
 *  添加请求地址: 如果地址不合法不添加;如果地址在推荐栏中,不添加; 如果是已经存在的地址添加
 *
 *  @param host eg: http://www.hid.s:8080
 *
 *  @return 操作结果
 */
+ (BOOL)addHost:(NSString*)host {
    
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];

    if ([host isEqualToString:[userDefaults objectForKey:RECOMMEND_SERVER]]) {
        // [[BDHUD sharedManager] showWords:@"系统推荐服务器地址"];
        return NO;
    }
    
    NSMutableArray *hostArray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:ADD_SERVERS]];
    for (NSString *existHost in hostArray) {
        if ([host isEqualToString:existHost]) {
            // [[BDHUD sharedManager] showWords:@"已存在服务器地址"];
            return NO;
        }
    }
    NSInteger beforeAdd = hostArray.count;
    [hostArray addObject:host];
    [userDefaults setObject:hostArray forKey:ADD_SERVERS];
    NSInteger afterAdd = hostArray.count;
    if (beforeAdd == afterAdd) {
//        [[BDHUD sharedManager] showWords:@"添加失败"];
        return NO;
    }
    return YES;
}



/**
 设置从特定服务器中获取的TXT文本中的服务器地址: 1.如果TXT文本中服务器地址为不为空, 设置推荐服务器地址为TXT文本中的服务器地址;如果为空,将宏定义的HOST作为推荐使用的服务器地址. 2 在系统推荐服务器地址已经设置成功时,如果当前使用的服务器地址还为空,就设置推荐使用的服务器地址为当前APP使用的服务器地址

 @param host 为从特定服务器中的TXT文本中获取的服务器地址
 */
+ (void)setRecommendHost:(NSString *)host {
    
    NSString *severHost = [[NSUserDefaults standardUserDefaults] objectForKey:RECOMMEND_SERVER];
    
     [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:RECOMMEND_SERVER];
    
    if (![Toolobject IsEmptyString:host
          ] && [host hasPrefix:@"http://"]) {
        
        [[NSUserDefaults standardUserDefaults] setObject:host forKey:RECOMMEND_SERVER];
    }
    else {
        if ([Toolobject IsEmptyString:severHost]){
            [[NSUserDefaults standardUserDefaults] setObject:HOST forKey:RECOMMEND_SERVER];
        }
    }
}


/**
 *  删除服务器地址
 *
 *  @param index
 *
 *  @return 
 */
+ (BOOL)deleteHostAtIndex:(NSInteger)index {
    
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
    NSMutableArray *hostarray=[NSMutableArray arrayWithArray:[userDefaults objectForKey:ADD_SERVERS]];
  
    NSInteger deleteBefore = hostarray.count;
    [hostarray removeObjectAtIndex:index];
    [userDefaults setObject:hostarray forKey:ADD_SERVERS];
    NSInteger deleteAfter = hostarray.count;
    if (deleteBefore == deleteAfter) {
        return NO;
    }
    return YES;

}

/**
 *  字典DES加密成字符串
 *
 *  @param sourceDict 源字典
*  @param bencrypt 是否加密
 *  @return 加密结果
 */
+(NSString*)encryption:(NSMutableDictionary*)sourceDict  encrypt:(BOOL)bencrypt{
    NSString *resultString=@"";
    if(!sourceDict){
        return resultString;
    }
    NSString *jsonString=[self dictionaryToJson:sourceDict];
    resultString=[jsonString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 
    if(bencrypt){
        //加密
        
       resultString= __DesEncodeString(resultString);
        
    }
    return resultString;
}
/**
 *  加密字符串DES解密成字典
 *
 *  @param sourceString 源字符串
*  @param bencrypt 是否加密
 *  @return 解密结果
 */
+(NSMutableDictionary*)decryption:(NSString*)sourceString  encrypt:(BOOL)bencrypt{
    NSMutableDictionary *resultDict=[[NSMutableDictionary alloc] initWithCapacity:0];
    if(!sourceString){
        return resultDict;
    }
    if(bencrypt){
        //字符串解密
       NSString * jsonString = __DesDecodeString(sourceString);
        jsonString=[UtilCheck stringreplace:jsonString Replace:@"+" Target:@" "];
        jsonString = [jsonString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSLog(@"解码后的请求结果是：%@",jsonString);
        
        resultDict = [[self dictionaryWithJsonString:jsonString] mutableCopy];
    }
    else{
       resultDict = [[self dictionaryWithJsonString:sourceString] mutableCopy];
    }
    
    
    
    return resultDict;
}




/**
 *倒计时 2016-23-23 23:23
 */
+(NSString *)timeHandle: (NSString *) theDate dateFormatter:(NSString*)formatter
{
    
    
    NSTimeInterval late=[[UtilCheck dateByString:theDate oldFormatter:formatter dateFormatter:@"yyyy-MM-dd HH:mm"] timeIntervalSince1970]*1;//[d timeIntervalSince1970]*1;
    
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    
    NSTimeInterval now=[dat timeIntervalSince1970]*1;
    
    NSString *timeString=@"";
 
    
    NSTimeInterval cha=(now-late);
    
    if(cha<1){
        return @"刚刚";
    }
    
    else if (cha/3600<1) {
        
        
        timeString = [NSString stringWithFormat:@"%f", cha/60];
        
        timeString = [timeString substringToIndex:timeString.length-7];
        
        timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
        
        
        
    }
    
    else if (cha/3600>1&&cha/86400<1) {
        
        timeString = [NSString stringWithFormat:@"%f", cha/3600];
        
        timeString = [timeString substringToIndex:timeString.length-7];
        
        timeString=[NSString stringWithFormat:@"%@小时前", timeString];
        
        timeString= [UtilCheck  stringByDate:[UtilCheck dateByString:theDate oldFormatter:formatter dateFormatter:@"yyyy-MM-dd HH:mm"] dateFormatter:@"HH:mm"];
        
    }
    
    else if (cha/86400>1&&cha/86400<7)
        
    {
        
        timeString = [NSString stringWithFormat:@"%f", cha/86400];
        
        timeString = [timeString substringToIndex:timeString.length-7];
        
        if([timeString isEqualToString:@"1"]){
          timeString=@"昨天";
        }
        else  if([timeString isEqualToString:@"2"]){
               timeString=@"前天";
                  }
        else{
        timeString=[NSString stringWithFormat:@"%@天前", timeString];
        }
        
    }
    else{
        timeString=[NSString stringWithFormat:@"一周前"];
    }
    
    
    
    
    return timeString;
    
    
}

/**
 *  获取路径文件名
 *
 *  @param url <#url description#>
 *
 *  @return <#return value description#>
 */
+(NSString*)getFileName:(NSString*)url{
    NSString *result=@"";
    if([url isKindOfClass:[NSURL class]]){
        url=[(NSURL*)url absoluteString];
    }
    if([UtilCheck DataIsNuLL:url ]){
        return result;
    }
    NSArray *arr=[url componentsSeparatedByString:@","];
    NSInteger count=arr.count;
    for(int i=0;i<count;i++){
        NSString *oString=arr[i];
        NSArray *stringArray=[oString componentsSeparatedByString:@"/"];
        if(stringArray.count>0){
            result=[NSString stringWithFormat:@"%@%@,",result,stringArray[stringArray.count-1]];
        }
    }
    if([result hasSuffix:@","]){
        result=[result substringToIndex:result.length-1];
        
    }
    return result;
}

/*修改保存当前操作行*/
+(void)setWorkRow:(NSInteger)row{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
 
     [user setObject:@(row) forKey:ROW];
 
    [user synchronize];

    
}
/*获取保存当前操作行*/
+(int)getWorkRow{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
 
    return [[user objectForKey:ROW] intValue];
}

/*修改保存当前操作列*/
+(void)setWorkLow:(NSInteger)low{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    
    [user setObject:@(low) forKey:LOW];
    
    [user synchronize];
    
    
}
/*获取保存当前操作列*/
+(int)getWorkLow{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    
    return [[user objectForKey:LOW] intValue];
}

/**
 *  返回订单步骤文字
 *
 *  @return
 */
+(NSString *)approvalText:(NSInteger)code{
  
 
    
    switch (code) {
        case 0:
            return @"项目需求";
            break;
        case 1:
            return @"订单申请";
            break;
        case 2:
            return @"订单审批";
            break;
        case 3:
            return @"计划安排";
            break;
        case 4:
            return @"技术资料";
            break;
        case 5:
            return @"半成品";
            break;
        case 6:
            return @"黑件出厂";
            break;
        case 7:
            return @"镀锌申请";
            break;
        case 8:
            return @"镀锌申请-副总";
            break;
        case 9:
            return @"白件质检";
            break;
        case 10:
            return @"计划发货";
            break;
        case 11:
            return @"项目收货";
            break;
        case 12:
            return @"新建项目施工";
            break;
        case 13:
            return @"质量管理";
            break;
        case 14:
            return @"计划安排副总审批";
            break;
        case 15:
            return @"施工-改造";
            break;
        case 16:
            return @"施工-零星";
            break;

        case 17:
            return @"完工";
            break;
        default:
            return @"未知";
            break;
    }
    
}

/**
 *  创建审批数据模型
 *
 *  @param type 类似
 *
 *  @return 数组
 */
+(NSMutableArray*)createReViewModel:(NSInteger)type{
    NSMutableArray *table=[[NSMutableArray alloc] initWithCapacity:0];
    switch (type) {
        case 1:
        {
            //订单申请
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setValue:@"" forKey:@"content"];//审核意见
            [model setValue:@"1" forKey:@"status"];//审核默认状态
            [table addObject:model];
            
        }
            break;
        case 2:
        {
            //订单审批
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setValue:@"" forKey:@"content"];//审核意见
            [model setValue:@"1" forKey:@"status"];//审核默认状态
            [table addObject:model];
            
        }
            break;
        case 3:
        {
            //计划安排
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setValue:@"" forKey:@"planTime"];//审核意见
            [model setValue:@"1" forKey:@"isOS"];//审核默认状态
            [table addObject:model];
            
        }
            break;
        case 4:
        {
            //技术资料
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setObject:@"" forKey:@"boltTab"];
            [model setObject:@"" forKey:@"drawing"];
            [model setObject:@"" forKey:@"model"];
            [model setObject:@"" forKey:@"onePiece"];
            [model setObject:@"" forKey:@"remark"];
            [table addObject:model];
            
        }
            break;
        case 5:
        {
            //半成品
            //a个批次
            for(int a=0;a<2;a++){
                
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [model setObject:@"" forKey:@"content"];
                [model setObject:@"0" forKey:@"status"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchId"];
                
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchOrderBY"];
                
                NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                //i个班组
                for(int i=0;i<2;i++){
                    NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"",@"itemId",@"",@"itemName",@"",@"itemCount", nil];
                    [arr addObject:semile];
                }
                [model setObject:arr forKey:@"batch"];//批次
                
                [table addObject:model];
            }
            
            
        }
            break;
        case 6:
        {
            //黑件出厂
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            
            model = @{@"content":@"",@"status":@1,@"batchId":@"101",@"batchOrderBY":@1,@"itemId":@"1",@"itemName":@"3",@"itemCount":@"150",@"hasproblem":@1,@"BPCheck":@[@{@"checkId":@"001",@"checkName":@"SS",@"photo":@"http://13.13.13.26:2011/Order//upload/images/8(20160721153808).png",@"remark":@"Tatty"}]}.mutableCopy;
            [table addObject:model];
            
        }
            break;
        case 7:
        {
            //镀锌申请
            for(int a=0;a<2;a++){
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [ model setObject:@"" forKey:@"content"];
                [ model setObject:@"0" forKey:@"status"];
                [ model setObject:@"0" forKey:@"itemId"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchId"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchOrderBY"];
                [ model setObject:@"(3)班" forKey:@"itemName"];
                [ model setObject:@"20" forKey:@"itemCount"];
                
                NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                //审核项
                for(int i=0;i<2;i++){
                    NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"GVIbatchId",[NSString stringWithFormat:@"%d",i+1],@"GVIbatchOrderBY",@"",@"gviTowerId",@"",@"gviTowerName",@"",@"givVerderName",@"",@"gviPrice",@"",@"gviCount",@"",@"gviSTme",@"",@"gviETime", nil];
                    [arr addObject:semile];
                }
                [ model setObject:arr forKey:@"GVI"];//批次
                
                
                [table addObject:model];
                
            }
            
            
        }
            break;
        case 8:
        {
            
            //镀锌申请审核-副总
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [ model setObject:@"" forKey:@"content"];
            [ model setObject:@"0" forKey:@"status"];
            [table addObject:model];
            
        }
            break;
        case 9:
        {
            //白件质检
            for(int b=0;b<2;b++){
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [ model setObject:@"" forKey:@"content"];
                [ model setObject:@"0" forKey:@"status"];
                [ model setObject:@"0" forKey:@"itemId"];
                                [model setObject:[NSString stringWithFormat:@"%d",b+1] forKey:@"batchId"];
                [model setObject:[NSString stringWithFormat:@"%d",b+1] forKey:@"batchOrderBY"];
                [ model setObject:@"(3)班" forKey:@"itemName"];
                [ model setObject:@"20" forKey:@"itemCount"];
                NSMutableArray *gviArray=[[NSMutableArray alloc] initWithCapacity:0];
                //a个批次
                for(int a=0;a<2;a++){
                    NSMutableDictionary *itemDict=[[NSMutableDictionary alloc] initWithCapacity:0];
                  [itemDict setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"gvibatchId"];
                    [itemDict setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"gvibatchOrderBY"];
                    [itemDict setObject:@"0" forKey:@"problem"];
                    [itemDict setObject:@"AA工程厂" forKey:@"givVerderName"];
                    NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                    //审核项
                    for(int i=0;i<2;i++){
                        NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"gviCheckbatchId",[NSString stringWithFormat:@"%d",i+1],@"gviCheckbatchOrderBY",@"",@"checkId",@"",@"checkName",@"",@"photo", nil];
                        [arr addObject:semile];
                    }
                    [itemDict setObject:arr forKey:@"check"];//批次
                    
                    [gviArray addObject:itemDict];
                    
                }
                [ model setObject:gviArray forKey:@"GVIcheck"];
                
                [table addObject:model];
                
            }
            
        }
            break;
        case 10:
        {
            //计划发货
            
            //a个批次
            for(int a=0;a<2;a++){
                
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [model setObject:@"" forKey:@"content"];
                [model setObject:@"0" forKey:@"status"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchId"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchOrderBY"];
                
                [model setObject:@"1" forKey:@"itemId"];
                [model setObject:@"（3）班" forKey:@"itemName"];
                [model setObject:@"10" forKey:@"itemCount"];
                
                NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                //镀锌厂家
                for(int i=0;i<2;i++){
                    
                    NSDictionary *dictEMS=[NSDictionary dictionaryWithObjectsAndKeys:@"",@"EMSId",@"",@"EMSName",@"",@"EMSUserName",@"",@"EMSCar",@"",@"EMSstartTime",@"",@"EMSendtime", nil];
                    NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"gviCheckbatchId",[NSString stringWithFormat:@"%d",i+1],@"gviCheckbatchOrderBY",@"1",@"gviTowerId",@"三角塔",@"gviTowerName",@"AA工程厂",@"gviVerderName",dictEMS,@"EMS", nil];
                    [arr addObject:semile];
                }
                [model setObject:arr forKey:@"GVIcheck"];//批次
                
                [table addObject:model];
            }
            
            
        }
            break;
        case 11:
        {
            //项目收货
            //a个批次
            for(int a=0;a<2;a++){
                
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [model setObject:@"" forKey:@"content"];
                [model setObject:@"0" forKey:@"status"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchId"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"batchOrderBY"];
                
                [model setObject:@"1" forKey:@"itemId"];
                [model setObject:@"（3）班" forKey:@"itemName"];
                [model setObject:@"10" forKey:@"itemCount"];
                
                NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                //镀锌厂家
                for(int i=0;i<2;i++){
                    
                    NSDictionary *dictEMS=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"EMSId",@"快递公司一",@"EMSName",@"张三",@"EMSUserName",@"湘A 888888",@"EMSCar",@"2016-07-12",@"EMSstartTime",@"2016-07-16",@"EMSendtime",@"",@"endtime", nil];
                    NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"gviCheckbatchId",[NSString stringWithFormat:@"%d",i+1],@"gviCheckbatchOrderBY",@"1",@"gviTowerId",@"三角塔",@"gviTowerName",@"AA工程厂",@"gviVerderName",dictEMS,@"EMS", nil];
                    [arr addObject:semile];
                }
                [model setObject:arr forKey:@"GVIcheck"];//批次
                
                [table addObject:model];
            }
        }
            break;
        case 12:
        {
            //新建施工
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setObject:@"" forKey:@"CCTId"];
            [model setObject:@"" forKey:@"CCTName"];
            [model setObject:@"" forKey:@"startTime"];
            [model setObject:@"" forKey:@"endtime"];
            [model setObject:@"" forKey:@"remark"];
            [table addObject:model];
            
        }
            break;
        case 13:
        {
            //施工质检
            //a个批次
            for(int a=0;a<2;a++){
                
                NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
                [model setObject:@"" forKey:@"content"];
                [model setObject:@"0" forKey:@"status"];
                 [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"CCTbatchId"];
                [model setObject:[NSString stringWithFormat:@"%d",a+1] forKey:@"CCTbatchOrderBY"];
                [model setObject:@"0" forKey:@"problem"];
                
                NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:0];
                //施工队无
                for(int i=0;i<2;i++){
                    NSDictionary *semile=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"CCTCheckbatchId",[NSString stringWithFormat:@"%d",i+1],@"CCTCheckbatchOrderBY",@"",@"qualityId",@"",@"qualityName",@"",@"photo",@"",@"price",@"",@"remark", nil];
                    [arr addObject:semile];
                }
                [model setObject:arr forKey:@"CCTcheck"];//批次
                
                [table addObject:model];
            }
            
            
        }
            break;
        case 14:
        {
            //计划安排副总审核
            NSMutableDictionary *model=[[NSMutableDictionary alloc] initWithCapacity:0];
            [model setObject:@"" forKey:@"content"];
            [model setObject:@"1" forKey:@"status"];
            
            [table addObject:model];
            
        }
            break;
        default:
            break;
    }
    return table;
    
}

+(LanguageType)getLanageType{
    
    NSNumber *number =[[NSUserDefaults standardUserDefaults] objectForKey:@"LANGUAGE"];
    if(number){
        return [number integerValue];
    }
    return  NSLanguageDefault;
}


+ (LanguageType)getPreferredLanguage

{
    NSArray *languages = [NSLocale preferredLanguages];
    NSString * preferredLang = [languages objectAtIndex:0];
    NSLog(@"preferredLang is --%@",preferredLang);
    
    if ([preferredLang hasPrefix:@"zh"]) {
        return NSLanguageChineese;
    }
    else {
        return NSLanguageEnglish;
    }
}
/**
 *  电话号码隐匿
 *
 *  @param iphone 电话号码
 *  @param flag  隐匿字符
 *
 *  @return
 */
+(NSString*)TelHidden:(NSString*)iphone Symbol:(NSString*)flag{
    
    NSString *str=@"***";
    if(!(flag&&[flag isKindOfClass:[NSString class]])){
        flag=@"*";
    }
    if([self isValidateMobile:iphone]){
        str=[NSString stringWithFormat:@"%@****%@",[iphone substringToIndex:3],[iphone substringFromIndex:iphone.length-4]];
        
    }
    return str;
    
}
/**
 *  根据编号返回操作权限名称
 *
 *  @param code   操作权限，1取消订单2修改订单，3安排发货，4确认订单，5继续发货，6确认收货，7查看物流，8快速发货，9发货
 *
 *  @return
 */
+(NSString*)operationText:(NSString*)code{
    NSString *operationString=@"";
    if([code isKindOfClass:[NSString class]]){
        
        operationString=[THMangerTool language:[NSString stringWithFormat:@"operation.code%@",code]];
 
        
    }
    
    return operationString;
    
}

/**
 *  根据编号返回发货选项
 *
 *  @param code   operationPermissions":1安排发货，2快速发货，3发货
 *
 *  @return
 */
+(NSString*)operationPermissions:(NSString*)code{
    NSString *operationString=@"";
    if([code isKindOfClass:[NSString class]]){
        
        operationString=[THMangerTool language:[NSString stringWithFormat:@"operationPermission.code%@",code]];
        
        
    }
    
    return operationString;
    
}

/**
 *  根据编号返回发货选项
 *
 *  @param code   operationPermissions":1手动添加，2扫码添加，3打包，4安排发货
 *
 *  @return
 */
+(NSString*)operationDeliver:(NSString*)code{
    NSString *operationString=@"";
    if([code isKindOfClass:[NSString class]]){
        
        operationString=[THMangerTool language:[NSString stringWithFormat:@"operationDeliver.code%@",code]];
        
        
    }
    
    return operationString;
    
}


/**
 *  数据深拷贝 相当于深拷贝一份data。这样才不会改变data本身的值
 *
 *  @param data 数据
 *
 *  @return 放回结果
 */
+(id)deepCopy:(id)data{
    //相当于深拷贝一份data。这样才不会改变data本身的值
    return [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:data]];
}



@end
